package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.Useragreement;
import com.ruoyi.system.service.IUseragreementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户协议管理Controller
 *
 * @author ruoyi
 * @date 2024-10-30
 */
@RestController
@RequestMapping("/useragreement")
public class UseragreementController extends BaseController
{
    @Autowired
    private IUseragreementService useragreementService;

    /**
     * 查询用户协议管理列表
     */
    @RequiresPermissions("system:useragreement:list")
    @GetMapping("/list")
    public TableDataInfo list(Useragreement useragreement)
    {
        startPage();
        List<Useragreement> list = useragreementService.selectUseragreementList(useragreement);
        return getDataTable(list);
    }

    /**
     * 导出用户协议管理列表
     */
    @RequiresPermissions("system:useragreement:export")
    @Log(title = "用户协议管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Useragreement useragreement)
    {
        List<Useragreement> list = useragreementService.selectUseragreementList(useragreement);
        ExcelUtil<Useragreement> util = new ExcelUtil<Useragreement>(Useragreement.class);
        util.exportExcel(response, list, "用户协议管理数据");
    }

    /**
     * 获取用户协议管理详细信息
     */
    @RequiresPermissions("system:useragreement:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(useragreementService.selectUseragreementById(id));
    }

    /**
     * 新增用户协议管理
     */
    @RequiresPermissions("system:useragreement:add")
    @Log(title = "用户协议管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Useragreement useragreement)
    {
        return toAjax(useragreementService.insertUseragreement(useragreement));
    }

    /**
     * 修改用户协议管理
     */
    @RequiresPermissions("system:useragreement:edit")
    @Log(title = "用户协议管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Useragreement useragreement)
    {
        return toAjax(useragreementService.updateUseragreement(useragreement));
    }

    /**
     * 删除用户协议管理
     */
    @RequiresPermissions("system:useragreement:remove")
    @Log(title = "用户协议管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(useragreementService.deleteUseragreementByIds(ids));
    }
}
